<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"><meta name="format-detection" content="telephone=no">
    <title>local-photoselect</title>
    <link rel="stylesheet" href="../plugin/seedsui/seedsui.min.css">
</head>

<body>
    <section id="page_local_photoselect" class="active">
        <header>
            <div class="titlebar">
                <a href="javascript:back()"><i class="icon icon-arrowleft"></i></a>
                <h1>照片选择</h1>
            </div>
        </header>
        <article>
            <div class="card padding8">
                目前只支持ios和部分android浏览器
            </div>
            <div class="row">
                <label>图片上传</label>
                <div class="input-box margin8">
                    <input type="file" id="takePicture" accept="image/*" multiple />
                </div>
            </div>
        	<br/>
        	<div class="sliver">上传的图片</div>
            <ul class="grid album" data-col="3" id="photoshow"></ul>
        </article>
    </section>
    
    <script src="../plugin/jquery/jquery.min.js"></script>
    <script src="../plugin/seedsui/seedsui.min.js"></script>
    <!--Exmobi能力-->
    <script src="../plugin/exmobi/exmobi.js"></script>
    <!--禁止ios弹性-->
    <script src="../plugin/inobounce/inobounce.min.js"></script>
    <script>
    function fileSelect(fileId,handler){
    	var takePicture=document.querySelector(fileId);
        //监听上传控件事件
        takePicture.onchange = function (e) {
            var files = event.target.files;
            var filepath=null;
            for(var i=0,file;file=files[i++];){
                try {
                    var URL = window.URL || window.webkitURL;
                    filePath = URL.createObjectURL(file);
                    handler(filePath);
                    URL.revokeObjectURL(filePath);
                }
                catch (e) {
                    try {
                        var fileReader = new FileReader();
                        fileReader.onload = function (event) {
                            filePath= event.target.result;
                            handler(filePath);
                        };
                        fileReader.readAsDataURL(file);
                    }
                    catch (e) {
                        alert("此设备即不支持createObjectURL也不支持FileReader");
                    }
                }
            }
        };
    };
    fileSelect("#takePicture",function(path){
        if(path){
    	   $("#photoshow").append('<li><a style="background-image: url('+path+')"></a></li>');
        }
    });
    //定义exmobi返回
    function back(){history.go(-1);}
    </script>
</body>
</html>
